home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QRZ! Ham Radio 8
/
QRZ Ham Radio Callsign Database - Volume 8.iso
/
mac
/
files
/
infodata
/
callbook.tar
/
callbook_1.3
/
misc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-03-31
|
3KB
|
184 lines
/*
* Telnet callsign server sources copyright 1989 by Devon Bowen, KA2NRC.
* You may distribute and modify these files as you please as long as
* as long as credit to the original creator is given. Please report any
* bug fixes or modification to bowen@cs.buffalo.edu.
*/
#include <stdio.h>
#include <ctype.h>
#include <syslog.h>
char *index();
/*
* strhash - given a pointer to a string, hash it based on the
* upper case characters in the string and return an unsigned
* int in the range 0-65535.
*/
unsigned short
strhash(str)
char *str;
{
int hash = 0;
for (; *str != '\0' && *str != '|'; str++) {
if (islower(*str))
hash = (hash * 29 + *str - 96) % 65536;
if (isupper(*str))
hash = (hash * 29 + *str - 64) % 65536;
if (isdigit(*str))
hash = (hash * 29 + *str - 48) % 65536;
}
return((unsigned short) hash);
}
strcasecpy(to, from)
char *to, *from;
{
while (*from) {
if (islower(*from))
*to++ = toupper(*from);
else
*to++ = *from;
from++;
}
*to = '\0';
}
/*
* my_fgets - given the normal parameters to fgets, get the line
* and zero out the '\n' at the end of the string (if there is one).
*/
char *
my_fgets(buf, num, fd)
char *buf;
int num;
FILE *fd;
{
char *n;
if (fgets(buf, num, fd)) {
if (n = index(buf, '\n'))
*n = '\0';
return(buf);
} else
return(NULL);
}
paramnum(str)
char *str;
{
int count=0;
while (isspace(*str))
str++;
while (*str) {
if (*str == '"') {
str++;
while (*str && *str != '"')
str++;
if (*str)
str++;
else
return(-1);
} else
while (*str && !isspace(*str))
str++;
while (isspace(*str))
str++;
count++;
}
return(count);
}
char *
param(str, num)
char *str;
int num;
{
static char buffer[BUFSIZ];
int bufcnt=0;
while (isspace(*str))
str++;
while (*str && num) {
if (*str == '"') {
str++;
while (*str && *str != '"')
str++;
if (*str)
str++;
} else
while (*str && !isspace(*str))
str++;
while (isspace(*str))
str++;
num--;
}
if (num || (*str == '\0'))
return(NULL);
if (*str == '"') {
str++;
while (*str && *str != '"') {
buffer[bufcnt++] = *str;
str++;
}
} else
while (*str && !isspace(*str)) {
buffer[bufcnt++] = *str;
str++;
}
buffer[bufcnt] = '\0';
return(buffer);
}
stvalid(state)
char *state;
{
int count = 0;
static char *states[] = {
"AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE",
"FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS",
"KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS",
"MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY",
"NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC",
"SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV",
"WI", "WY", "VI", NULL
};
while (states[count] && strcasecmp(states[count], state))
count++;
return (states[count] ? 1 : 0);
}